Skip to content

Conversation

@colinmurphy
Copy link
Member

@colinmurphy colinmurphy commented Dec 10, 2024

Overview:

I converted the header and footer menus into static menus using a JSON array.
The purpose of this task was firstly to remove the loading text on the initial page load and also to add SSR.

One tradeoff was around having 3 menus or just one menu for the footer which we could filter. I considered 3 menus but I found that the code was cleaner with one menu and I was able to filter each section.

QA

  1. Manually checked that both header and footer links matched what was on the current development site
  2. Manually opening all links to make sure they all worked

Screenshots below

image Screenshot 2024-12-10 at 13 42 55 Screenshot 2024-12-10 at 13 43 50

@colinmurphy colinmurphy changed the base branch from canary to toolkit December 10, 2024 13:46
@headless-platform-by-wp-engine

Check out the recent updates to your Headless Platform preview environment:

App Environment URL Build
faustjs.org preview-env-feature/convert-menus-to-json https://hu…wered.com ✅ (logs)

Learn more about preview environments in our documentation.

Copy link
Contributor

@kellenmace kellenmace left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@colinmurphy So, you executed on the new JSON file approach for this feature beautifully, but now seeing it implemented, I'm wondering if maybe this approach is unnecessarily complex. 😅

What if we just hardcode the menu links directly in the primary-nav and footer files?

The menus are not used anywhere else in the app, so there's no real reason why they need to live in a separate menus.js file. And with the current approach, we have to jump through a bunch of hoops:

  • Add unique ids for the menu items so that when we map over them we can pass those in as the key prop to appease React
  • Add a section property for every object to keep track of which column it's supposed to be in.
  • Do filtering in the footer file to sort the menu items in three lists
  • Map over the menu items and render the nav links

If we hardcode the nav links directly in the primary-nav and footer files, we could wipe out all of those steps and simplify this code significantly. We'd have to repeat the className class lists for each column and nav link, but I don't have a problem with that.

What do you think of this simpler hardcoding approach, @colinmurphy & @Fran-A-Dev?

target: "_blank",
},
{
id: "dicord",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo here– missing an "s". Not that it matters too much, since this is just a unique ID that end users never see :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Kellen :)

export const PRIMARY_LOCATION = "PRIMARY";
export const FOOTER_LOCATION = "FOOTER_1";

export const HeaderMenu = [
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would name this using camelCase instead of PascalCase here. By convention, PascalCase is typically used for classes and React components and camelCase is used for other variables like this array. When I first glanced at this PR and saw HeaderMenu, my first thought was that it was a React component that was being imported.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Kellen, That is really useful feedback. I wasn't aware of the different conventions for React. Thank you.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ya same with the HeaderMenu in my mind being a React component.


return columns.map((column, index) => {
if (!column || column.length === 0) {
return; // Skip rendering if no menu items are found
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per this section of the React docs (https://react.dev/learn/conditional-rendering#conditionally-returning-nothing-with-null), the recommended way to render nothing is to return null. So this line should do that.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Kellen, That is good to know.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Kellen for the really good feedback. I can definitely see where your coming from and I agree with your approach too. There is definitely too much overhead for some static links which are not going to be re-used elsewhere. We could also probably set a variable for the class names to try and reduce repetition too.

@Fran-A-Dev
Copy link
Contributor

@colinmurphy So, you executed on the new JSON file approach for this feature beautifully, but now seeing it implemented, I'm wondering if maybe this approach is unnecessarily complex. 😅

What if we just hardcode the menu links directly in the primary-nav and footer files?

The menus are not used anywhere else in the app, so there's no real reason why they need to live in a separate menus.js file. And with the current approach, we have to jump through a bunch of hoops:

  • Add unique ids for the menu items so that when we map over them we can pass those in as the key prop to appease React
  • Add a section property for every object to keep track of which column it's supposed to be in.
  • Do filtering in the footer file to sort the menu items in three lists
  • Map over the menu items and render the nav links

If we hardcode the nav links directly in the primary-nav and footer files, we could wipe out all of those steps and simplify this code significantly. We'd have to repeat the className class lists for each column and nav link, but I don't have a problem with that.

What do you think of this simpler hardcoding approach, @colinmurphy & @Fran-A-Dev?

Agreed @kellenmace , this is how I would do it myself as well. Keeping this as simple as possible. I tend to hardcode things whenever possible and if it is the best approach to keep it simple.

@headless-platform-by-wp-engine

Check out the recent updates to your Headless Platform preview environment:

App Environment URL Build
faustjs.org preview-env-feature/convert-menus-to-json https://hu…wered.com ✅ (logs)

Learn more about preview environments in our documentation.

@colinmurphy
Copy link
Member Author

@kellenmace @Fran-A-Dev

The PR has now been updated as per code review (thanks for the feedback) and the links are now hardcoded.

@moonmeister
Copy link
Member

I disagree completely with Kellen and Fran but 🤷‍♂️. The first system was over engineered but directly replaced the JS API without engineering the HTML/CSS. You didn't need the id or targut fields. And sections could have been achieved by simply exporting multiple objects instead of doing the complex filtering.

Kellen can make the call but I would have refined the previous idea instead of re-engineering something that has to be undone when we revert to WP menus.

className={linkClass}
href="https://www.npmjs.com/package/@faustwp/cli"
noDefaultStyles
target="_blank"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is handled by the component.

</li>
</ul>
</div>
<div className={columnClass} key="community">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keys are unneeded if we're not mapping over an array.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@colinmurphy @kellenmace @moonmeister I am for whatever ya'll decide is best! Stoked

@colinmurphy
Copy link
Member Author

Thanks Alex for the feedback. I won't do anything further here until Kellen reviews. Happy to do either approach. In hindsight the filter approach was a bit too complex and going with 3 objects instead would of been the better approach.

@Fran-A-Dev
Copy link
Contributor

Thanks Alex for the feedback. I won't do anything further here until Kellen reviews. Happy to do either approach. In hindsight the filter approach was a bit too complex and going with 3 objects instead would of been the better approach.

@Fran-A-Dev Fran-A-Dev closed this Dec 11, 2024
@kellenmace kellenmace reopened this Dec 11, 2024
@headless-platform-by-wp-engine

Check out the recent updates to your Headless Platform preview environment:

App Environment URL Build
faustjs.org preview-env-feature/convert-menus-to-json https://hj…wered.com ✅ (logs)

Learn more about preview environments in our documentation.

@colinmurphy
Copy link
Member Author

@kellenmace @Fran-A-Dev @moonmeister This is now ready to be reviewed again. As per call I removed the key and target elements. I also double checked that privacy policy link does not open a new window too.

@colinmurphy colinmurphy marked this pull request as ready for review December 11, 2024 18:15
@headless-platform-by-wp-engine

Check out the recent updates to your Headless Platform preview environment:

App Environment URL Build
faustjs.org preview-env-feature/convert-menus-to-json https://hj…wered.com ✅ (logs)

Learn more about preview environments in our documentation.

@headless-platform-by-wp-engine

Check out the recent updates to your Headless Platform preview environment:

App Environment URL Build
faustjs.org preview-env-feature/convert-menus-to-json https://hj…wered.com ✅ (logs)

Learn more about preview environments in our documentation.

Copy link
Contributor

@kellenmace kellenmace left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This last iteration looks great to me. Thanks @colinmurphy! 👍🏼

@kellenmace kellenmace merged commit b5ffb44 into toolkit Dec 12, 2024
3 checks passed
@kellenmace kellenmace deleted the feature/convert-menus-to-json branch December 12, 2024 18:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: ✅ Closed

Development

Successfully merging this pull request may close these issues.

4 participants